//
//  NSError.swift
//  iUtil
//
//  Created by wendachuan on 19/3/22.
//  Copyright © 2019年 wendachuan. All rights reserved.
//

import Foundation

public extension NSError {

    /// 便利构造
    ///
    /// - parameter domain: 错误域
    /// - parameter errorCode: 错误代码
    /// - parameter errorDescription: 错误描述
    convenience init(domain: String? = nil, errorCode: Int, errorDescription: String) {
        self.init(domain: String.toNoneNIL(domain), code: errorCode, userInfo: [NSLocalizedDescriptionKey: errorDescription])
    }

    /// 返回包含错误代码和错误描述的字符串
    ///
    /// - returns: 包含错误代码和错误描述的字符串
    func stringValue() -> String {
        return "错误代码:\(code),错误信息:\(localizedDescription)"
    }
}
